package com.jiangtour.handler;

import com.jiangtour.VO.ResultVO;
import com.jiangtour.config.ProjectUrlConfig;
import com.jiangtour.exception.SiteAuthorizeException;
import com.jiangtour.exception.SiteException;
import com.jiangtour.utils.ResultVOUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author Administrator
 * @Title: SellExceptionHandler
 * @ProjectName site
 * @Description:
 * @date 2018/12/29/02916:01
 */

@ControllerAdvice
public class SiteExceptionHandler {
    @Autowired
    private ProjectUrlConfig projectUrlConfig;


    //拦截登陆异常
    @ExceptionHandler(value = SiteAuthorizeException.class)
    public ModelAndView handlerAuthorizeException() {
        return new ModelAndView("redirect:" + projectUrlConfig.getSite() + "/user/index");
    }

    @ExceptionHandler(value = SiteException.class)
    @ResponseBody
    public ResultVO handlerSellerException(SiteException e) {
        return ResultVOUtil.error(e.getCode(), e.getMessage());
    }

}
